package com.fml.ft_study.service;

import com.fml.ft_study.dao.DiningTableDAO;
import com.fml.ft_study.domain.DiningTable;

import java.util.List;

public class DiningTableService {
    private DiningTableDAO diningTableDAO=new DiningTableDAO();
    public List<DiningTable>list(){

        return diningTableDAO.queryMulti("SELECT id,state FROM diningTable;",DiningTable.class);
    }
    //根据Id返回diningTable对象
    public DiningTable getDiningTableById(String Id) {

    return diningTableDAO.querySingle("SELECT * FROM `diningtable`where  id=?",DiningTable.class,Id);

    }
    //成功预定之后修改表中的数据，返回修改是否成功
    public boolean updataById(String orderName,String ordertel){
        int update = diningTableDAO.update("UPDATE diningtable SET state='已经预定',orderName=?,orderTel=?WHERE id=1;", orderName, ordertel);
        return  update>0;
    }
    //在点菜之后更新桌子的状态
    public boolean updataDiningTable(int id,String state){
        int update = diningTableDAO.update("UPDATE diningTable set state=? where id=?", state, id);
        return update>0;
    }
    //根据餐桌号来返回餐桌是否存在
    public DiningTable diningTableById(int id){
        DiningTable diningTable = diningTableDAO.querySingle("SELECT * FROM  diningtable WHERE id=?", DiningTable.class, id);
        return diningTable;
    }
    //根据桌号将餐桌表置为初始状态
    public boolean setIinitDiningTable(int diningTable){

        int update = diningTableDAO.update("UPDATE diningtable set state='空',orderName='',orderTel=''WHERE id=?;", diningTable);
        if (update>0){
            return true;
        }
     return false;
    }
}
